package com.keelau.ui.fx;

import javafx.geometry.Orientation;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;

public class mainLayoutUI extends AnchorPane {

    SplitPane splitPane;
    public mainLayoutUI() {
        //super();
        ToolBar toolBar =  new ToolBar();

        ToggleButton toggleButton = new ToggleButton("显示");
        toggleButton.setSelected(true);
        ToggleButton toggleButton1 = new ToggleButton("隐藏");
        ToggleGroup toggleGroup =  new ToggleGroup();
        toggleButton.setToggleGroup(toggleGroup);
        toggleButton1.setToggleGroup(toggleGroup);
        toolBar.getItems().addAll(toggleButton,toggleButton1);

        BorderPane borderPane = new BorderPane();

        borderPane.setTop(toolBar);

        splitPane = new SplitPane();
        splitPane.setOrientation(Orientation.HORIZONTAL);

        splitPane.setDividerPositions(0.2);
        toggleButton1.setOnAction(event -> {
            if(splitPane.getItems().size()==2)
                splitPane.getItems().remove(0);
        });

        toggleButton.setOnAction(event -> {
            if(splitPane.getItems().size()==1) {
                splitPane.getItems().add(0, getLeftMenu());
                splitPane.setDividerPositions(0.2);
            }
        });

      //  splitPane.getItems().add(getLeftMenu());
        //splitPane.getItems().get(0).setLayoutX(100);
      //  splitPane.getItems().get(0).setScaleX(10);
        ComponentUtils.fillParent(borderPane);

        borderPane.setCenter(splitPane);
        getChildren().add(borderPane);

    }

    public void setRightMenu(Node node){
        splitPane.getItems().add(node);
    }

    public void setDiviDerPosition(double...  positions){
        splitPane.setDividerPositions(positions);
    }


    public Accordion getLeftMenu(){
        Accordion accordion = new Accordion();

        TitledPane titledPane1 = new TitledPane();

        titledPane1.setText("阿里工具");
        Button button1 = new Button("阿里单品抓取");

        titledPane1.setContent(button1);
        Button button2 = new Button("button2");
        titledPane1.setContent(button2);

        titledPane1.setMinWidth(0);

        accordion.getPanes().add(titledPane1);

        accordion.minWidth(0);
        accordion.setMaxWidth(300);

        return accordion;
    }
}
